package com.dms.service.impl;

import com.dms.mapper.RepairManageMapper;
import com.dms.pojo.Building;
import com.dms.pojo.Repair;
import com.dms.service.RepairManageService;
import com.dms.utils.ConstantUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @className: RepairManageServiceImpl
 * @package: com.dms.service.impl
 * @description 后勤服务的报修模块的业务逻辑层实现类
 * @author: sk
 */
@Service
public class RepairManageServiceImpl implements RepairManageService {

    @Autowired
    RepairManageMapper repairManageMapper;

    /**
     * 获取楼栋列表
     * @return
     */
    @Override
    public List<Building> getBuildingList() {
        return repairManageMapper.getBuildingList();
    }

    /**
     * 模糊查询报修列表
     * @param query
     * @param select
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<Repair> getRepairListLimit(String query, Integer select, String startData, String endData,int pageNum, int pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("query", query);
        map.put("select", select);
        map.put("startData", startData);
        map.put("endData", endData);
        map.put("start", (pageNum - 1) * pageSize);
        map.put("size", pageSize);
        return repairManageMapper.getRepairListLimit(map);
    }

    /**
     * 获取total
     * @param query
     * @param select
     * @return
     */
    @Override
    public int getRepairTotal(String query, Integer select, String startData, String endData) {
        Map<String, Object> map = new HashMap<>();
        map.put("query", query);
        map.put("select", select);
        map.put("startData", startData);
        map.put("endData", endData);
        return repairManageMapper.getRepairTotal(map);
    }

    /**
     * 设置报修解决时间
     * @param processingTime
     * @return
     */
    @Override
    public int updateProcessingTime(Integer repairId, String processingTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("repairId", repairId);
        map.put("processingTime", processingTime);
        map.put("isProcessing", ConstantUtil._ISPROCESSING);
        return repairManageMapper.updateProcessingTime(map);
    }

    /**
     * 根据id删除报修信息
     * @param repairId
     * @return
     */
    @Override
    public int deleteRepair(Integer repairId) {
        return repairManageMapper.deleteRepair(repairId);
    }

    /**
     * 物品报修申请
     * @param dormitoryId
     * @param repairTime
     * @param repairReason
     * @return
     */
    @Override
    public int addRepair(String dormitoryId, String repairTime, String repairReason) {
        Map<String, Object> map = new HashMap<>();
        map.put("dormitoryId", dormitoryId);
        map.put("repairTime", repairTime);
        map.put("repairReason", repairReason);
        map.put("isProcessing", ConstantUtil._NOPROCESSING);
        return repairManageMapper.addRepair(map);
    }
}
